#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//1000个字符, 加上'\0', 至少需要1001
#define N 1010

int substitute(char *str, char oldchar, char newchar)
{
    int count = 0;
    while (*str) {
        if (*str == oldchar) {
            count++;
            *str = newchar;
        }
        str++;
    }
    return count;
}

int main()
{
    char *str = NULL, oldchar, newchar;
    str = (char *)malloc(sizeof(char) * N);
    if (str == NULL)
        return 1;
    while (scanf("%s %c %c", str, &oldchar, &newchar) == 3)
    {
        printf("%d %s\n", substitute(str, oldchar, newchar), str);
    }

    free(str);
    str = NULL; //养成释放内存后赋值为NULL的好习惯
    return 0;
}
